import React, { Component } from 'react';
import {Layout,  Menu, Icon, Badge } from 'antd';
import avater from '../images/header.jpg';
import {withRouter} from "react-router-dom";


const {Header} = Layout;
const SubMenu = Menu.SubMenu;
const MenuItemGroup = Menu.ItemGroup;

class Headertar extends Component {
    state = {
        isLogin: document.cookie.includes('login=true')
    }  
    setCookie = (key, value, day) => {
        let expires = day * 86400 * 1000  // 时间转化成 ms
        let date = new Date( + new Date() + expires) // 当前时间加上要存储的时间
        document.cookie = `${key}=${value};expires=${date.toUTCString()}`
    }
    loginout = () => {
        console.log(this);
        this.setCookie('login', '', -1);
        console.log(this);
        this.props.history.push('/Login'); 
    }

 

    
    render() {
        return (

            <Header style={{ background: '#fff', padding: 0 }} >
                <Menu
                    mode="horizontal"
                    style={{ lineHeight: '64px', float: 'right' }}
                >
                    <Menu.Item key="1">
                        <Badge count={25} overflowCount={10} style={{marginLeft: 10}}>
                            <Icon type="notification" />
                        </Badge>
                    </Menu.Item>
                    <SubMenu title={<span className="avatar"><img src={avater} alt="头像" style={{ height:'30px',width:'30px' }}/><i className="on bottom b-white" /></span>}>
                        <MenuItemGroup title="用户中心">
                            <Menu.Item key="setting:1">你好</Menu.Item>
                            <Menu.Item key="setting:2">个人信息</Menu.Item>
                            <Menu.Item key="logout" onClick={this.loginout}><span>退出登录</span></Menu.Item>
                        </MenuItemGroup>
                        <MenuItemGroup title="设置中心">
                            <Menu.Item key="setting:3">个人设置</Menu.Item>
                            <Menu.Item key="setting:4">系统设置</Menu.Item>
                        </MenuItemGroup>
                    </SubMenu>
                </Menu>
            </Header>
        )
    }
}

export default withRouter(Headertar);
